package com.yt.base.util.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JacksonDateDeserializer extends JsonDeserializer<Date> {
	private static final Logger logger = LoggerFactory.getLogger(JacksonDateDeserializer.class);

	public JacksonDateDeserializer() {
	}

	public Date deserialize(JsonParser parser, DeserializationContext arg1) throws IOException, JsonProcessingException {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			return sdf.parse(parser.getText());
		} catch (ParseException e) {
			logger.error("ParseException: ", e);
		}
		return null;
	}
	//
	// public Object deserialize(JsonParser jsonparser,
	// DeserializationContext deserializationcontext) throws IOException,
	// JsonProcessingException {
	// return deserialize(jsonparser, deserializationcontext);
	// }

}
